package com.gjy.sql.oracle.newland.finance;

import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-07-15 09:05:02
 */
public class BlankRowInsertHandler implements RowWriteHandler {

    private final Integer blankRowCount;

    public BlankRowInsertHandler(Integer blankRowCount) {
        this.blankRowCount = blankRowCount;
    }

    @Override
    public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
                                Row row, Integer relativeRowIndex, Boolean isHead) {
        // 仅在非表头行后插入空行
        if (!isHead) {
            Sheet sheet = writeSheetHolder.getSheet();
            int lastRowNum = sheet.getLastRowNum();
            for (int i = 0; i < blankRowCount; i++) {
                sheet.createRow(lastRowNum + i + 1); // 创建空行
            }
        }

    }

}
